package dasregistry.utils;

import java.util.List;

import org.biojava.dasobert.dasregistry.DasSource;


import org.biojava.services.das2.DasSourceProvider;

/**
 * to store some of the registry responses or objects
 * @author jw12
 *
 */
public class RegistryCache {
	
	List <DasSource>das1sources;
	Long lastUpdate;//last time data was updated
	
	public List <DasSource> getDas1Sources(DasSourceProvider das1provider, Long lastModified){
		
		
	    //Long lastUpdate = (Long) timeCache.get(url);
	    long twentyFourHours = System.currentTimeMillis(  ) - 60*60*1000*24;
//System.out.println("last modified="+lastModified);
//System.out.println(" last updated="+lastUpdate);
	    if (das1sources == null || das1sources.size() == 0 ||
	        lastUpdate == null || (lastUpdate.longValue(  ) < twentyFourHours)|| (lastModified > lastUpdate)) {
	    	System.out.println("updating sources in cache");
	    	das1sources = das1provider.getDasSources();
	    	lastUpdate=System.currentTimeMillis(  );
	    }
	    System.out.println("got das1sources");
		
		return das1sources;
	}
	

}
